package elements.labels; 
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.events.Event;
import flash.text.TextFieldAutoSize;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import string.Utils;
import string.Css;

class YLegendBase extends Sprite {
	
	public var tf:TextField;
	
	public var text:String;
	public var style:String;
	var css:Css;
	
	//	[Embed(source = "C:\\Windows\\Fonts\\Verdana.ttf", fontFamily = "foo", fontName = '_Verdana')]
	//	private static var EMBEDDED_FONT:String;
			
	//	[Embed(systemFont='Arial', fontName='spArial', mimeType='application/x-font')]
	//	public static var ArialFont:Class;
	
	/*[Embed(systemFont='Arial', fontName='spArial', mimeType='application/x-font')]*/
	// TODO - figure out what this is supposed to do...
	//public static var ArialFont:Class; 
	
	public function new( json:Dynamic, name:String )
	{
		super();
		if( json[name+'_legend'] == undefined )
			return;
			
		if( json[name+'_legend'] )
		{
			Object_helper.merge_2( json[name+'_legend'], this );
		}
		
		this.css = new Css( this.style );
		
		this.build( this.text );
	}
	
	function build( text:String ): Void {
		var title:TextField = new TextField();

		title.x = 0;
		title.y = 0;
		
		var format:TextFormat = new TextFormat();
		format.color = this.css.color;
		format.font = "spArial";
		format.size = this.css.font_size;
		format.align = "center";
		
		title.htmlText = text;
		title.setTextFormat(format);
		title.autoSize = "left";
		title.embedFonts = true;
		title.rotation = 270;
		title.height = title.textHeight;
		title.antiAliasType = AntiAliasType.ADVANCED;
		title.autoSize = TextFieldAutoSize.LEFT;

		this.addChild(title);
	}
	
	public function resize():Void {
		if ( this.text == null )
			return;
	}
	
	public function get_width(): Float {
		if( this.numChildren == 0 )
			return 0;
		else
			return this.getChildAt(0).width;
	}
	
	public function die(): Void {
		
		while ( this.numChildren > 0 )
			this.removeChildAt(0);
	}
}
